Windows Server 2022 で Windows Subsystem for Linux 2 (WSL 2) が使えるようになりました

Windows Server 2022 で Windows Subsystem for Linux 2 (WSL 2) が使えるようになりました

Windows Server 2022でもWSL 2は使えるぞ
Clock Icon2022.06.24

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Windows ServerでもWSL 2を使いたいな

こんにちは、のんピ(@non____97)です。

皆さんはWindows ServerでWindows Subsystem for Linux 2(以降、WSL 2)を使いたいと思ったことはありますか? 私はあります。

私はWindows 10やWindows 11のマシンを持っていないので、WSL 2に触れる機会がありませんでした。

以下の記事を見てからというもの、触ってみたいと常日頃思っていました。

そんな折、Windows Server 2022でWSL 2が使えるようなったとアナウンスがありました。

これは試すしかない

ということで、Windows Server 2022のEC2インスタンスでWSL 2を起動できるか試してみました。

いきなりまとめ

  • WSL 2を使用するにはハードウェアレベルで仮想化をサポートしている必要がある
  • AWS上でWSL 2を使用するにはベアメタルインスタンス上で動作させる必要がある
  • wsl --installはWSLの機能有効化前に行う必要がある
  • 手動でWSLの機能を有効化した場合は以下操作を行う必要がある
    • WSL 2 Linux カーネル更新プログラムのインストール
    • VirtualMachinePlatform機能の有効化
  • wsl --installでの設定が簡単

Windows Server 2022でやってみた

インスタンスタイプの選定

早速、やってみます。

WSL 2を使用するにはハードウェアレベルで仮想化をサポートしている必要があります。

通常のインスタンスタイプではEC2インスタンス上に仮想マシンのハイパーバイザーを立てる、Nested Virtualizationをサポートしていません。そのため、仮想化レイヤを経由せずに直接Intel VT-xなどのハードウェアへのアクセスが可能なベアメタルインスタンスを使う必要があります。

実際、ベアメタルインスタンスでないt3.microのEC2インスタンスでWSL 2をインストールして、Ubuntu 20.04を起動しようとすると、以下のようなエラーが出力されます。

t3.microでWSL 2をインストールして、Ubuntu 20.04を起動

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80370102
Error: 0x80370102 The virtual machine could not be started because a required feature is not installed.

Press any key to continue...

t3.microで起動したEC2インスタンスのシステム情報を確認すると、ハイパーバイザーが検出されたことにより、Hyper-Vに必要な機能は表示されませんでした。

PS C:\Windows\system32> systeminfo

Host Name:                 EC2AMAZ-DPKA9LC
OS Name:                   Microsoft Windows Server 2022 Datacenter
OS Version:                10.0.20348 N/A Build 20348
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
Registered Owner:          EC2
Registered Organization:   Amazon.com
Product ID:                00454-60000-00001-AA527
Original Install Date:     6/23/2022, 8:04:18 AM
System Boot Time:          6/23/2022, 9:22:12 AM
System Manufacturer:       Amazon EC2
System Model:              t3.micro
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 4 GenuineIntel ~2500 Mhz
BIOS Version:              Amazon EC2 1.0, 10/16/2017
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC) Coordinated Universal Time
Total Physical Memory:     996 MB
Available Physical Memory: 410 MB
Virtual Memory: Max Size:  2,020 MB
Virtual Memory: Available: 1,105 MB
Virtual Memory: In Use:    915 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              N/A
Hotfix(s):                 3 Hotfix(s) Installed.
                           [01]: KB5013890
                           [02]: KB5014678
                           [03]: KB5014030
Network Card(s):           1 NIC(s) Installed.
                           [01]: Amazon Elastic Network Adapter
                                 Connection Name: Ethernet
                                 DHCP Enabled:    Yes
                                 DHCP Server:     172.31.0.1
                                 IP address(es)
                                 [01]: 172.31.10.163
                                 [02]: fe80::14df:4a22:9e59:159
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

一方、ベアメタルインスタンスであるm5zn.metalでシステム情報を確認すると、ファームウェアレベルで仮想化が有効になっていることをOSから認識できます。

PS C:\Windows\system32> systeminfo

Host Name:                 EC2AMAZ-N3F7GIK
OS Name:                   Microsoft Windows Server 2022 Datacenter
OS Version:                10.0.20348 N/A Build 20348
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
Registered Owner:          EC2
Registered Organization:   Amazon.com
Product ID:                00454-60000-00001-AA588
Original Install Date:     6/23/2022, 6:33:46 AM
System Boot Time:          6/23/2022, 6:42:07 AM
System Manufacturer:       Amazon EC2
System Model:              m5zn.metal
System Type:               x64-based PC
Processor(s):              2 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 7 GenuineIntel ~3800 Mhz
                           [02]: Intel64 Family 6 Model 85 Stepping 7 GenuineIntel ~3800 Mhz
BIOS Version:              Amazon EC2 1.0, 10/16/2017
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              N/A
Time Zone:                 (UTC) Coordinated Universal Time
Total Physical Memory:     196,241 MB
Available Physical Memory: 192,096 MB
Virtual Memory: Max Size:  200,081 MB
Virtual Memory: Available: 196,102 MB
Virtual Memory: In Use:    3,979 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              N/A
Hotfix(s):                 3 Hotfix(s) Installed.
                           [01]: KB5013890
                           [02]: KB5014678
                           [03]: KB5014030
Network Card(s):           1 NIC(s) Installed.
                           [01]: Amazon Elastic Network Adapter
                                 Connection Name: Ethernet 3
                                 DHCP Enabled:    Yes
                                 DHCP Server:     172.31.0.1
                                 IP address(es)
                                 [01]: 172.31.3.55
                                 [02]: fe80::f806:43c1:2e49:728f
Hyper-V Requirements:      VM Monitor Mode Extensions: Yes
                           Virtualization Enabled In Firmware: Yes
                           Second Level Address Translation: Yes
                           Data Execution Prevention Available: Yes

タスクマネージャーからもVirtualizationEnabledになっていることが分かります。

VirtualizationがEnabled

OSのビルド番号の確認

次に、OSのビルド番号の確認を行います。

先ほどのMicrosoft公式ブログによると、2022年5月24日のKB5014021(OSビルド20348.740)がインストールされている必要があるようです。

2022/6/23時点で最新のWindows Server 2022のAMIであるWindows_Server-2022-English-Full-Base-2022.06.15 (ami-0e1a729017e59e409)でEC2インスタンスを起動してOSのビルド番号を確認します。

起動したEC2インスタンス上のコマンドプロンプトからOSのビルド番号が20348.740以上になっていることを確認します。

C:\Windows\system32>ver

Microsoft Windows [Version 10.0.20348.768]

20348.768であることから前提条件は満たしているようです。

WSL 2の起動

それでは、先ほどのMicrosoft公式ブログに従い、WSL 2のインストール、起動を行います。

まず、WSLの機能を有効化します。

# 機能一覧の確認
PS C:\Windows\system32> Get-WindowsFeature

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[ ] Active Directory Certificate Services               AD-Certificate                 Available
    [ ] Certification Authority                         ADCS-Cert-Authority            Available
    [ ] Certificate Enrollment Policy Web Service       ADCS-Enroll-Web-Pol            Available
    [ ] Certificate Enrollment Web Service              ADCS-Enroll-Web-Svc            Available
    [ ] Certification Authority Web Enrollment          ADCS-Web-Enrollment            Available
    [ ] Network Device Enrollment Service               ADCS-Device-Enrollment         Available
    [ ] Online Responder                                ADCS-Online-Cert               Available
[ ] Active Directory Domain Services                    AD-Domain-Services             Available
[ ] Active Directory Federation Services                ADFS-Federation                Available
[ ] Active Directory Lightweight Directory Services     ADLDS                          Available
[ ] Active Directory Rights Management Services         ADRMS                          Available
    [ ] Active Directory Rights Management Server       ADRMS-Server                   Available
    [ ] Identity Federation Support                     ADRMS-Identity                 Available
[ ] Device Health Attestation                           DeviceHealthAttestat...        Available
[ ] DHCP Server                                         DHCP                           Available
[ ] DNS Server                                          DNS                            Available
[ ] Fax Server                                          Fax                            Available
[X] File and Storage Services                           FileAndStorage-Services        Installed
    [ ] File and iSCSI Services                         File-Services                  Available
        [ ] File Server                                 FS-FileServer                  Available
        [ ] BranchCache for Network Files               FS-BranchCache                 Available
        [ ] Data Deduplication                          FS-Data-Deduplication          Available
        [ ] DFS Namespaces                              FS-DFS-Namespace               Available
        [ ] DFS Replication                             FS-DFS-Replication             Available
        [ ] File Server Resource Manager                FS-Resource-Manager            Available
        [ ] File Server VSS Agent Service               FS-VSS-Agent                   Available
        [ ] iSCSI Target Server                         FS-iSCSITarget-Server          Available
        [ ] iSCSI Target Storage Provider (VDS and V... iSCSITarget-VSS-VDS            Available
        [ ] Server for NFS                              FS-NFS-Service                 Available
        [ ] Work Folders                                FS-SyncShareService            Available
    [X] Storage Services                                Storage-Services               Installed
[ ] Host Guardian Service                               HostGuardianServiceRole        Available
[ ] Hyper-V                                             Hyper-V                        Available
[ ] Network Controller                                  NetworkController              Available
[ ] Network Policy and Access Services                  NPAS                           Available
[ ] Print and Document Services                         Print-Services                 Available
    [ ] Print Server                                    Print-Server                   Available
    [ ] Internet Printing                               Print-Internet                 Available
    [ ] LPD Service                                     Print-LPD-Service              Available
[ ] Remote Access                                       RemoteAccess                   Available
    [ ] DirectAccess and VPN (RAS)                      DirectAccess-VPN               Available
    [ ] Routing                                         Routing                        Available
    [ ] Web Application Proxy                           Web-Application-Proxy          Available
[ ] Remote Desktop Services                             Remote-Desktop-Services        Available
    [ ] Remote Desktop Connection Broker                RDS-Connection-Broker          Available
    [ ] Remote Desktop Gateway                          RDS-Gateway                    Available
    [ ] Remote Desktop Licensing                        RDS-Licensing                  Available
    [ ] Remote Desktop Session Host                     RDS-RD-Server                  Available
    [ ] Remote Desktop Virtualization Host              RDS-Virtualization             Available
    [ ] Remote Desktop Web Access                       RDS-Web-Access                 Available
[ ] Volume Activation Services                          VolumeActivation               Available
[ ] Web Server (IIS)                                    Web-Server                     Available
    [ ] Web Server                                      Web-WebServer                  Available
        [ ] Common HTTP Features                        Web-Common-Http                Available
            [ ] Default Document                        Web-Default-Doc                Available
            [ ] Directory Browsing                      Web-Dir-Browsing               Available
            [ ] HTTP Errors                             Web-Http-Errors                Available
            [ ] Static Content                          Web-Static-Content             Available
            [ ] HTTP Redirection                        Web-Http-Redirect              Available
            [ ] WebDAV Publishing                       Web-DAV-Publishing             Available
        [ ] Health and Diagnostics                      Web-Health                     Available
            [ ] HTTP Logging                            Web-Http-Logging               Available
            [ ] Custom Logging                          Web-Custom-Logging             Available
            [ ] Logging Tools                           Web-Log-Libraries              Available
            [ ] ODBC Logging                            Web-ODBC-Logging               Available
            [ ] Request Monitor                         Web-Request-Monitor            Available
            [ ] Tracing                                 Web-Http-Tracing               Available
        [ ] Performance                                 Web-Performance                Available
            [ ] Static Content Compression              Web-Stat-Compression           Available
            [ ] Dynamic Content Compression             Web-Dyn-Compression            Available
        [ ] Security                                    Web-Security                   Available
            [ ] Request Filtering                       Web-Filtering                  Available
            [ ] Basic Authentication                    Web-Basic-Auth                 Available
            [ ] Centralized SSL Certificate Support     Web-CertProvider               Available
            [ ] Client Certificate Mapping Authentic... Web-Client-Auth                Available
            [ ] Digest Authentication                   Web-Digest-Auth                Available
            [ ] IIS Client Certificate Mapping Authe... Web-Cert-Auth                  Available
            [ ] IP and Domain Restrictions              Web-IP-Security                Available
            [ ] URL Authorization                       Web-Url-Auth                   Available
            [ ] Windows Authentication                  Web-Windows-Auth               Available
        [ ] Application Development                     Web-App-Dev                    Available
            [ ] .NET Extensibility 3.5                  Web-Net-Ext                    Available
            [ ] .NET Extensibility 4.8                  Web-Net-Ext45                  Available
            [ ] Application Initialization              Web-AppInit                    Available
            [ ] ASP                                     Web-ASP                        Available
            [ ] ASP.NET 3.5                             Web-Asp-Net                    Available
            [ ] ASP.NET 4.8                             Web-Asp-Net45                  Available
            [ ] CGI                                     Web-CGI                        Available
            [ ] ISAPI Extensions                        Web-ISAPI-Ext                  Available
            [ ] ISAPI Filters                           Web-ISAPI-Filter               Available
            [ ] Server Side Includes                    Web-Includes                   Available
            [ ] WebSocket Protocol                      Web-WebSockets                 Available
    [ ] FTP Server                                      Web-Ftp-Server                 Available
        [ ] FTP Service                                 Web-Ftp-Service                Available
        [ ] FTP Extensibility                           Web-Ftp-Ext                    Available
    [ ] Management Tools                                Web-Mgmt-Tools                 Available
        [ ] IIS Management Console                      Web-Mgmt-Console               Available
        [ ] IIS 6 Management Compatibility              Web-Mgmt-Compat                Available
            [ ] IIS 6 Metabase Compatibility            Web-Metabase                   Available
            [ ] IIS 6 Management Console                Web-Lgcy-Mgmt-Console          Available
            [ ] IIS 6 Scripting Tools                   Web-Lgcy-Scripting             Available
            [ ] IIS 6 WMI Compatibility                 Web-WMI                        Available
        [ ] IIS Management Scripts and Tools            Web-Scripting-Tools            Available
        [ ] Management Service                          Web-Mgmt-Service               Available
[ ] Windows Deployment Services                         WDS                            Available
    [ ] Deployment Server                               WDS-Deployment                 Available
    [ ] Transport Server                                WDS-Transport                  Available
[ ] Windows Server Update Services                      UpdateServices                 Available
    [ ] WID Connectivity                                UpdateServices-WidDB           Available
    [ ] WSUS Services                                   UpdateServices-Services        Available
    [ ] SQL Server Connectivity                         UpdateServices-DB              Available
[ ] .NET Framework 3.5 Features                         NET-Framework-Features         Available
    [ ] .NET Framework 3.5 (includes .NET 2.0 and 3.0)  NET-Framework-Core               Removed
    [ ] HTTP Activation                                 NET-HTTP-Activation            Available
    [ ] Non-HTTP Activation                             NET-Non-HTTP-Activ             Available
[X] .NET Framework 4.8 Features                         NET-Framework-45-Fea...        Installed
    [X] .NET Framework 4.8                              NET-Framework-45-Core          Installed
    [ ] ASP.NET 4.8                                     NET-Framework-45-ASPNET        Available
    [X] WCF Services                                    NET-WCF-Services45             Installed
        [ ] HTTP Activation                             NET-WCF-HTTP-Activat...        Available
        [ ] Message Queuing (MSMQ) Activation           NET-WCF-MSMQ-Activat...        Available
        [ ] Named Pipe Activation                       NET-WCF-Pipe-Activat...        Available
        [ ] TCP Activation                              NET-WCF-TCP-Activati...        Available
        [X] TCP Port Sharing                            NET-WCF-TCP-PortShar...        Installed
[ ] Background Intelligent Transfer Service (BITS)      BITS                           Available
    [ ] IIS Server Extension                            BITS-IIS-Ext                   Available
    [ ] Compact Server                                  BITS-Compact-Server            Available
[ ] BitLocker Drive Encryption                          BitLocker                      Available
[ ] BitLocker Network Unlock                            BitLocker-NetworkUnlock        Available
[ ] BranchCache                                         BranchCache                    Available
[ ] Client for NFS                                      NFS-Client                     Available
[ ] Containers                                          Containers                     Available
[ ] Data Center Bridging                                Data-Center-Bridging           Available
[ ] Direct Play                                         Direct-Play                    Available
[ ] Enhanced Storage                                    EnhancedStorage                Available
[ ] Failover Clustering                                 Failover-Clustering            Available
[ ] Group Policy Management                             GPMC                           Available
[ ] Host Guardian Hyper-V Support                       HostGuardian                   Available
[ ] I/O Quality of Service                              DiskIo-QoS                     Available
[ ] IIS Hostable Web Core                               Web-WHC                        Available
[ ] Internet Printing Client                            Internet-Print-Client          Available
[ ] IP Address Management (IPAM) Server                 IPAM                           Available
[ ] LPR Port Monitor                                    LPR-Port-Monitor               Available
[ ] Management OData IIS Extension                      ManagementOdata                Available
[ ] Media Foundation                                    Server-Media-Foundation        Available
[ ] Message Queuing                                     MSMQ                           Available
    [ ] Message Queuing Services                        MSMQ-Services                  Available
        [ ] Message Queuing Server                      MSMQ-Server                    Available
        [ ] Directory Service Integration               MSMQ-Directory                 Available
        [ ] HTTP Support                                MSMQ-HTTP-Support              Available
        [ ] Message Queuing Triggers                    MSMQ-Triggers                  Available
        [ ] Multicasting Support                        MSMQ-Multicasting              Available
        [ ] Routing Service                             MSMQ-Routing                   Available
    [ ] Message Queuing DCOM Proxy                      MSMQ-DCOM                      Available
[X] Microsoft Defender Antivirus                        Windows-Defender               Installed
[ ] Multipath I/O                                       Multipath-IO                   Available
[ ] MultiPoint Connector                                MultiPoint-Connector           Available
    [ ] MultiPoint Connector Services                   MultiPoint-Connector...        Available
    [ ] MultiPoint Manager and MultiPoint Dashboard     MultiPoint-Tools               Available
[ ] Network Load Balancing                              NLB                            Available
[ ] Network Virtualization                              NetworkVirtualization          Available
[ ] Peer Name Resolution Protocol                       PNRP                           Available
[ ] Quality Windows Audio Video Experience              qWave                          Available
[ ] RAS Connection Manager Administration Kit (CMAK)    CMAK                           Available
[ ] Remote Assistance                                   Remote-Assistance              Available
[ ] Remote Differential Compression                     RDC                            Available
[ ] Remote Server Administration Tools                  RSAT                           Available
    [ ] Feature Administration Tools                    RSAT-Feature-Tools             Available
        [ ] SMTP Server Tools                           RSAT-SMTP                      Available
        [ ] BitLocker Drive Encryption Administratio... RSAT-Feature-Tools-B...        Available
            [ ] BitLocker Drive Encryption Tools        RSAT-Feature-Tools-B...        Available
            [ ] BitLocker Recovery Password Viewer      RSAT-Feature-Tools-B...        Available
        [ ] BITS Server Extensions Tools                RSAT-Bits-Server               Available
        [ ] DataCenterBridging LLDP Tools               RSAT-DataCenterBridg...        Available
        [ ] Failover Clustering Tools                   RSAT-Clustering                Available
            [ ] Failover Cluster Management Tools       RSAT-Clustering-Mgmt           Available
            [ ] Failover Cluster Module for Windows ... RSAT-Clustering-Powe...        Available
            [ ] Failover Cluster Automation Server      RSAT-Clustering-Auto...        Available
            [ ] Failover Cluster Command Interface      RSAT-Clustering-CmdI...        Available
        [ ] IP Address Management (IPAM) Client         IPAM-Client-Feature            Available
        [ ] Network Load Balancing Tools                RSAT-NLB                       Available
        [ ] Shielded VM Tools                           RSAT-Shielded-VM-Tools         Available
        [ ] SNMP Tools                                  RSAT-SNMP                      Available
        [ ] Storage Migration Service Tools             RSAT-SMS                       Available
        [ ] Storage Replica Module for Windows Power... RSAT-Storage-Replica           Available
        [ ] System Insights Module for Windows Power... RSAT-System-Insights           Available
        [ ] WINS Server Tools                           RSAT-WINS                      Available
    [ ] Role Administration Tools                       RSAT-Role-Tools                Available
        [ ] AD DS and AD LDS Tools                      RSAT-AD-Tools                  Available
            [ ] Active Directory module for Windows ... RSAT-AD-PowerShell             Available
            [ ] AD DS Tools                             RSAT-ADDS                      Available
                [ ] Active Directory Administrative ... RSAT-AD-AdminCenter            Available
                [ ] AD DS Snap-Ins and Command-Line ... RSAT-ADDS-Tools                Available
            [ ] AD LDS Snap-Ins and Command-Line Tools  RSAT-ADLDS                     Available
        [ ] Hyper-V Management Tools                    RSAT-Hyper-V-Tools             Available
            [ ] Hyper-V GUI Management Tools            Hyper-V-Tools                  Available
            [ ] Hyper-V Module for Windows PowerShell   Hyper-V-PowerShell             Available
        [ ] Remote Desktop Services Tools               RSAT-RDS-Tools                 Available
            [ ] Remote Desktop Gateway Tools            RSAT-RDS-Gateway               Available
            [ ] Remote Desktop Licensing Diagnoser T... RSAT-RDS-Licensing-D...        Available
            [ ] Remote Desktop Licensing Tools          RDS-Licensing-UI               Available
        [ ] Windows Server Update Services Tools        UpdateServices-RSAT            Available
            [ ] API and PowerShell cmdlets              UpdateServices-API             Available
            [ ] User Interface Management Console       UpdateServices-UI              Available
        [ ] Active Directory Certificate Services Tools RSAT-ADCS                      Available
            [ ] Certification Authority Management T... RSAT-ADCS-Mgmt                 Available
            [ ] Online Responder Tools                  RSAT-Online-Responder          Available
        [ ] Active Directory Rights Management Servi... RSAT-ADRMS                     Available
        [ ] DHCP Server Tools                           RSAT-DHCP                      Available
        [ ] DNS Server Tools                            RSAT-DNS-Server                Available
        [ ] Fax Server Tools                            RSAT-Fax                       Available
        [ ] File Services Tools                         RSAT-File-Services             Available
            [ ] DFS Management Tools                    RSAT-DFS-Mgmt-Con              Available
            [ ] File Server Resource Manager Tools      RSAT-FSRM-Mgmt                 Available
            [ ] Services for Network File System Man... RSAT-NFS-Admin                 Available
        [ ] Network Controller Management Tools         RSAT-NetworkController         Available
        [ ] Network Policy and Access Services Tools    RSAT-NPAS                      Available
        [ ] Print and Document Services Tools           RSAT-Print-Services            Available
        [ ] Remote Access Management Tools              RSAT-RemoteAccess              Available
            [ ] Remote Access GUI and Command-Line T... RSAT-RemoteAccess-Mgmt         Available
            [ ] Remote Access module for Windows Pow... RSAT-RemoteAccess-Po...        Available
        [ ] Volume Activation Tools                     RSAT-VA-Tools                  Available
        [ ] Windows Deployment Services Tools           WDS-AdminPack                  Available
[ ] RPC over HTTP Proxy                                 RPC-over-HTTP-Proxy            Available
[ ] Setup and Boot Event Collection                     Setup-and-Boot-Event...        Available
[ ] Simple TCP/IP Services                              Simple-TCPIP                   Available
[ ] SMB 1.0/CIFS File Sharing Support                   FS-SMB1                        Available
    [ ] SMB 1.0/CIFS Client                             FS-SMB1-CLIENT                 Available
    [ ] SMB 1.0/CIFS Server                             FS-SMB1-SERVER                 Available
[ ] SMB Bandwidth Limit                                 FS-SMBBW                       Available
[ ] SMTP Server                                         SMTP-Server                    Available
[ ] SNMP Service                                        SNMP-Service                   Available
    [ ] SNMP WMI Provider                               SNMP-WMI-Provider              Available
[ ] Software Load Balancer                              SoftwareLoadBalancer           Available
[ ] Storage Migration Service                           SMS                            Available
[ ] Storage Migration Service Proxy                     SMS-Proxy                      Available
[ ] Storage Replica                                     Storage-Replica                Available
[X] System Data Archiver                                System-DataArchiver            Installed
[ ] System Insights                                     System-Insights                Available
[ ] Telnet Client                                       Telnet-Client                  Available
[ ] TFTP Client                                         TFTP-Client                    Available
[ ] VM Shielding Tools for Fabric Management            FabricShieldedTools            Available
[ ] WebDAV Redirector                                   WebDAV-Redirector              Available
[ ] Windows Biometric Framework                         Biometric-Framework            Available
[ ] Windows Identity Foundation 3.5                     Windows-Identity-Fou...        Available
[ ] Windows Internal Database                           Windows-Internal-Dat...        Available
[X] Windows PowerShell                                  PowerShellRoot                 Installed
    [X] Windows PowerShell 5.1                          PowerShell                     Installed
    [ ] Windows PowerShell 2.0 Engine                   PowerShell-V2                    Removed
    [ ] Windows PowerShell Desired State Configurati... DSC-Service                    Available
    [ ] Windows PowerShell Web Access                   WindowsPowerShellWeb...        Available
[ ] Windows Process Activation Service                  WAS                            Available
    [ ] Process Model                                   WAS-Process-Model              Available
    [ ] .NET Environment 3.5                            WAS-NET-Environment            Available
    [ ] Configuration APIs                              WAS-Config-APIs                Available
[ ] Windows Search Service                              Search-Service                 Available
[ ] Windows Server Backup                               Windows-Server-Backup          Available
[ ] Windows Server Migration Tools                      Migration                      Available
[ ] Windows Standards-Based Storage Management          WindowsStorageManage...        Available
[ ] Windows Subsystem for Linux                         Microsoft-Windows-Su...        Available
[ ] Windows TIFF IFilter                                Windows-TIFF-IFilter           Available
[ ] WinRM IIS Extension                                 WinRM-IIS-Ext                  Available
[ ] WINS Server                                         WINS                           Available
[ ] Wireless LAN Service                                Wireless-Networking            Available
[X] WoW64 Support                                       WoW64-Support                  Installed
[X] XPS Viewer                                          XPS-Viewer                     Installed

# WSLの機能が有効か確認
PS C:\Windows\system32> Get-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[ ] Windows Subsystem for Linux                         Microsoft-Windows-Su...        Available

# WSLの機能の有効化
PS C:\Windows\system32> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Do you want to restart the computer to complete this operation now?
[Y] Yes  [N] No  [?] Help (default is "Y"): Y


Path          :
Online        : True
RestartNeeded : True

WSLの機能を有効化すると再起動を求められるので、再起動します。ちなみにベアメタルインスタンスの起動・停止には時間がかかります。私の環境だと再起動に17分程度かかりました。

再起動に時間がかかる影響で、AWS基盤側では実行中となっているもののOSが立ち上がらない状態が続くと、システムステータス、インスタンスステータスの接続性チェックに失敗します。私は動揺しましたが、気長に待ちましょう。

システムステータス、インスタンスステータスの接続性チェックに失敗します

再起動後、WSLの機能が有効化されたか確認します。

PS C:\Windows\system32> Get-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] Windows Subsystem for Linux                         Microsoft-Windows-Su...        Installed

有効化されたようですね。

次に、wsl --installでWSL 2の設定をします。

PS C:\Windows\system32> wsl --install
Copyright (c) Microsoft Corporation. All rights reserved.

Usage: wsl.exe [Argument] [Options...] [CommandLine]

Arguments for running Linux binaries:

    If no command line is provided, wsl.exe launches the default shell.

    --exec, -e <CommandLine>
        Execute the specified command without using the default Linux shell.

    --
        Pass the remaining command line as is.

Options:
    --distribution, -d <Distro>
        Run the specified distribution.

    --user, -u <UserName>
        Run as the specified user.

Arguments for managing Windows Subsystem for Linux:

    --help
        Display usage information.

    --install [Options]
        Install additional Windows Subsystem for Linux distributions.
        For a list of valid distributions, use 'wsl --list --online'.

        Options:
            --distribution, -d [Argument]
                Downloads and installs a distribution by name.

                Arguments:
                    A valid distribution name (not case sensitive).

                Examples:
                    wsl --install -d Ubuntu
                    wsl --install --distribution Debian

    --set-default-version <Version>
        Changes the default install version for new distributions.

    --shutdown
        Immediately terminates all running distributions and the WSL 2
        lightweight utility virtual machine.

    --status
        Show the status of Windows Subsystem for Linux.

    --update [Options]
        If no options are specified, the WSL 2 kernel will be updated
        to the latest version.

        Options:
            --rollback
                Revert to the previous version of the WSL 2 kernel.

Arguments for managing distributions in Windows Subsystem for Linux:

    --export <Distro> <FileName>
        Exports the distribution to a tar file.
        The filename can be - for standard output.

    --import <Distro> <InstallLocation> <FileName> [Options]
        Imports the specified tar file as a new distribution.
        The filename can be - for standard input.

        Options:
            --version <Version>
                Specifies the version to use for the new distribution.

    --list, -l [Options]
        Lists distributions.

        Options:
            --all
                List all distributions, including distributions that are
                currently being installed or uninstalled.

            --running
                List only distributions that are currently running.

            --quiet, -q
                Only show distribution names.

            --verbose, -v
                Show detailed information about all distributions.

            --online, -o
                Displays a list of available distributions for install with 'wsl --install'.

    --set-default, -s <Distro>
        Sets the distribution as the default.

    --set-version <Distro> <Version>
        Changes the version of the specified distribution.

    --terminate, -t <Distro>
        Terminates the specified distribution.

    --unregister <Distro>
        Unregisters the distribution and deletes the root filesystem.

    --mount <Disk>
        Attaches and mounts a physical disk in all WSL2 distributions.

        Options:
            --bare
                Attach the disk to WSL2, but don't mount it.

            --type <Type>
                Filesystem to use when mounting a disk, if not specified defaults to ext4.

            --options <Options>
                Additional mount options.

            --partition <Index>
                Index of the partition to mount, if not specified defaults to the whole disk.

    --unmount [Disk]
        Unmounts and detaches a disk from all WSL2 distributions.
        Unmounts and detaches all disks if called without argument.

wslのコマンドヘルプが表示されました。

Microsoft公式ドキュメントを確認すると、WSLの機能を既に有効化している状態だと、wsl --installは動作しないようです。

上記のコマンドは、WSL がインストールされていない場合にのみ機能します。wsl --install を実行して WSL ヘルプ テキストが表示される場合は、wsl --list --online を実行して使用可能なディストリビューションの一覧を表示し、wsl --install -d を実行してディストリビューションをインストールしてみてください。

WSL のインストール | Microsoft Docs

事前にWSLの機能(Microsoft-Windows-Subsystem-Linux)を有効化する必要はなかったようですね。

WSLのデフォルトのバージョンを確認すると2となっていることからWSL 2ではあるようです。

PS C:\Windows\system32> wsl --status
Default Version: 2
Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.

それでは、公式ドキュメントに従って、使用可能なディストリビューションの一覧を表示して、Ubuntu 20.04をインストールします。

# 使用できるディストリビューション一覧を確認
PS C:\Windows\system32> wsl -l -o
The following is a list of valid distributions that can be installed.
Install using 'wsl --install -d <Distro>'.

NAME            FRIENDLY NAME
Ubuntu          Ubuntu
Debian          Debian GNU/Linux
kali-linux      Kali Linux Rolling
openSUSE-42     openSUSE Leap 42
SLES-12         SUSE Linux Enterprise Server v12
Ubuntu-16.04    Ubuntu 16.04 LTS
Ubuntu-18.04    Ubuntu 18.04 LTS
Ubuntu-20.04    Ubuntu 20.04 LTS

# Ubuntu 20.04のインストール
PS C:\Users\Administrator> wsl --install --distribution Ubuntu-20.04
Downloading: Ubuntu 20.04 LTS
Installing: Ubuntu 20.04 LTS
Ubuntu 20.04 LTS has been installed.
Launching Ubuntu 20.04 LTS...

すると、Ubuntu 20.04のウィンドウが開き、以下のようなエラーが出力されました。

0x800701bc WSL 2 requires an update to its kernel component

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x800701bc
Error: 0x800701bc WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel

Press any key to continue...

どうやらWSL 2で使用するLinuxカーネルを更新する必要があるようです。

PowerShellでパッケージをダウンロードしてきて、インストールします。

# WSL 2 Linux カーネル更新プログラムのパッケージのダウンロード
PS C:\Users\Administrator> Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -OutFile wsl_update_x64.msi

# WSL 2 Linux カーネル更新プログラムのインストール
PS C:\Users\Administrator> msiexec /i wsl_update_x64.msi /quiet

WSL 2 Linux カーネル更新プログラムのインストールが完了した後、再度Ubuntu 20.04を起動させます。すると、またしても以下のようなエラーが出力されました。

0x80370102 The virtual machine could not be started because a required feature is not installed.

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80370102
Error: 0x80370102 The virtual machine could not be started because a required feature is not installed.

Press any key to continue...

必要な機能がインストールされていないため、仮想マシンを起動できないようです。

調査したところ、VirtualMachinePlatformという機能を有効化する必要があるようです。早速有効化してあげます。

# VirtualMachinePlatform が有効化されているか確認
PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -featurename *Platform


FeatureName      : HypervisorPlatform
DisplayName      : Windows Hypervisor Platform
Description      : Enables virtualization software to run on the Windows hypervisor
RestartRequired  : Possible
State            : Disabled
CustomProperties :


FeatureName      : VirtualMachinePlatform
DisplayName      : Virtual Machine Platform
Description      : Enables platform support for virtual machines
RestartRequired  : Possible
State            : Disabled
CustomProperties :

# VirtualMachinePlatform を有効化
PS C:\Windows\system32> Enable-WindowsOptionalFeature -online -featurename VirtualMachinePlatform
Do you want to restart the computer to complete this operation now?
[Y] Yes  [N] No  [?] Help (default is "Y"): Y


Path          :
Online        : True
RestartNeeded : True

VirtualMachinePlatformを有効化すると再起動を求められるので、再起動します。

再起動後、VirtualMachinePlatformが有効になったことを確認します。

PS C:\Users\Administrator> Get-WindowsOptionalFeature -Online -featurename *Platform


FeatureName      : HypervisorPlatform
DisplayName      : Windows Hypervisor Platform
Description      : Enables virtualization software to run on the Windows hypervisor
RestartRequired  : Possible
State            : Disabled
CustomProperties :


FeatureName      : VirtualMachinePlatform
DisplayName      : Virtual Machine Platform
Description      : Enables platform support for virtual machines
RestartRequired  : Possible
State            : Enabled
CustomProperties :

それでは、三度Ubuntu 20.04を起動させます。すると、ユーザー名の入力が求められました。

ユーザー名の入力

ユーザー名やパスワードを入力すると、Ubuntu 20.04が起動しました。感激です。

Ubuntu 20.04の起動確認

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: non-97
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Jun 23 09:36:27 UTC 2022

  System load:  0.13               Processes:             8
  Usage of /:   0.4% of 250.98GB   Users logged in:       0
  Memory usage: 0%                 IPv4 address for eth0: 172.21.136.241
  Swap usage:   0%

0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This message is shown once once a day. To disable it please create the
/home/non-97/.hushlogin file.
non-97@EC2AMAZ-N3F7GIK:~$

wsl -l -vwsl --statusでも確認します。WSL 2でUbuntu 20.04が起動しているようです。カーネルバージョンも表示されていますね。

PS C:\Users\Administrator> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         2

PS C:\Windows\system32> wsl --status
Default Version: 2

Windows Subsystem for Linux was last updated on 6/23/2022
The Windows Subsystem for Linux kernel can be manually updated with 'wsl --update', but automatic updates cannot occur due to your system settings.
To receive automatic kernel updates, please enable the Windows Update setting: 'Receive updates for other Microsoft products when you update Windows'.
For more information please visit https://aka.ms/wsl2kernel.

Kernel version: 5.10.16

OS情報を並べて現実であることを確認します。確かにWindows Server 2022でWSL 2が使用できていることが分かります。

確かにWindows Server 2022でWSL 2が使用できていることを確認

「wsl --install」で設定してみた

それでは、wsl --installだけでWSL 2の設定ができるのかも確認します。

Microsoft公式ドキュメントによると、wsl --installをすることで、以下の操作が行われるそうです。

  • オプションの WSL および仮想マシン プラットフォームのコンポーネントを有効にする
  • 最新の Linux カーネルをダウンロードしてインストールする
  • WSL 2 を既定値として設定する
  • Ubuntu Linux ディストリビューションをダウンロードしてインストールする

これはありがたいです。

新しくベアメタルインスタンスを起動して、wsl --installでWSL 2の設定を行います。

# システム情報の確認
PS C:\Windows\system32> systeminfo

Host Name:                 EC2AMAZ-KQ1VQ9H
OS Name:                   Microsoft Windows Server 2022 Datacenter
OS Version:                10.0.20348 N/A Build 20348
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
Registered Owner:          EC2
Registered Organization:   Amazon.com
Product ID:                00454-60000-00001-AA180
Original Install Date:     6/24/2022, 12:14:16 AM
System Boot Time:          6/24/2022, 12:20:20 AM
System Manufacturer:       Amazon EC2
System Model:              m5zn.metal
System Type:               x64-based PC
Processor(s):              2 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 7 GenuineIntel ~3800 Mhz
                           [02]: Intel64 Family 6 Model 85 Stepping 7 GenuineIntel ~3800 Mhz
BIOS Version:              Amazon EC2 1.0, 10/16/2017
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              N/A
Time Zone:                 (UTC) Coordinated Universal Time
Total Physical Memory:     196,241 MB
Available Physical Memory: 192,091 MB
Virtual Memory: Max Size:  200,081 MB
Virtual Memory: Available: 196,111 MB
Virtual Memory: In Use:    3,970 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              N/A
Hotfix(s):                 3 Hotfix(s) Installed.
                           [01]: KB5013890
                           [02]: KB5014678
                           [03]: KB5014030
Network Card(s):           1 NIC(s) Installed.
                           [01]: Amazon Elastic Network Adapter
                                 Connection Name: Ethernet 3
                                 DHCP Enabled:    Yes
                                 DHCP Server:     172.31.0.1
                                 IP address(es)
                                 [01]: 172.31.5.204
                                 [02]: fe80::adef:90c8:43b:77a7
Hyper-V Requirements:      VM Monitor Mode Extensions: Yes
                           Virtualization Enabled In Firmware: Yes
                           Second Level Address Translation: Yes
                           Data Execution Prevention Available: Yes

# WSL 2が設定されていないことを確認
PS C:\Windows\system32> wsl --status

Copyright (c) Microsoft Corporation. All rights reserved.

Usage: wsl.exe [Argument]

Arguments:

    --install <Options>
        Install Windows Subsystem for Linux features. If no options are specified,
        the recommended features will be installed along with the default distribution.

        To view the default distribution as well as a list of other valid distributions,
        use 'wsl --list --online'.

        Options:
            --distribution, -d [Argument]
                Specifies the distribution to be downloaded and installed by name.

                Arguments:
                    A valid distribution name (not case sensitive).

                Examples:
                    wsl --install -d Ubuntu
                    wsl --install --distribution Debian

    --list, -l [Options]
        Lists distributions.

        Options:
            --online, -o
                Displays a list of available distributions for install with 'wsl --install'.

    --help
        Display usage information.

# WSLの機能が有効化されていないことを確認
PS C:\Windows\system32> Get-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[ ] Windows Subsystem for Linux                         Microsoft-Windows-Su...        Available


# VirtualMachinePlatform が有効化されていないことを確認
PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -featurename *Platform


FeatureName      : HypervisorPlatform
DisplayName      : Windows Hypervisor Platform
Description      : Enables virtualization software to run on the Windows hypervisor
RestartRequired  : Possible
State            : Disabled
CustomProperties :


FeatureName      : VirtualMachinePlatform
DisplayName      : Virtual Machine Platform
Description      : Enables platform support for virtual machines
RestartRequired  : Possible
State            : Disabled
CustomProperties :

# WSL 2の設定
PS C:\Windows\system32> wsl --install
Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Downloading: WSL Kernel
Installing: WSL Kernel
WSL Kernel has been installed.
Downloading: Ubuntu
The requested operation is successful. Changes will not be effective until the system is rebooted.

# WSLの機能が有効化されたことを確認
PS C:\Windows\system32> Get-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] Windows Subsystem for Linux                         Microsoft-Windows-Su...        Installed

# VirtualMachinePlatform が有効化されたことを確認
PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -featurename *Platform


FeatureName      : HypervisorPlatform
DisplayName      : Windows Hypervisor Platform
Description      : Enables virtualization software to run on the Windows hypervisor
RestartRequired  : Possible
State            : Disabled
CustomProperties :


FeatureName      : VirtualMachinePlatform
DisplayName      : Virtual Machine Platform
Description      : Enables platform support for virtual machines
RestartRequired  : Possible
State            : Enabled
CustomProperties :

# 設定を反映させるためにOSを再起動
PS C:\Windows\system32> Restart-Computer

OS再起動後、WSL 2の設定がされたことを確認します。

# システム情報の確認
PS C:\Windows\system32> systeminfo

Host Name:                 EC2AMAZ-KQ1VQ9H
OS Name:                   Microsoft Windows Server 2022 Datacenter
OS Version:                10.0.20348 N/A Build 20348
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
Registered Owner:          EC2
Registered Organization:   Amazon.com
Product ID:                00454-60000-00001-AA180
Original Install Date:     6/24/2022, 12:14:16 AM
System Boot Time:          6/24/2022, 12:39:25 AM
System Manufacturer:       Amazon EC2
System Model:              m5zn.metal
System Type:               x64-based PC
Processor(s):              2 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 7 GenuineIntel ~3800 Mhz
                           [02]: Intel64 Family 6 Model 85 Stepping 7 GenuineIntel ~3800 Mhz
BIOS Version:              Amazon EC2 1.0, 10/16/2017
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              N/A
Time Zone:                 (UTC) Coordinated Universal Time
Total Physical Memory:     196,241 MB
Available Physical Memory: 190,544 MB
Virtual Memory: Max Size:  200,081 MB
Virtual Memory: Available: 194,549 MB
Virtual Memory: In Use:    5,532 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              N/A
Hotfix(s):                 3 Hotfix(s) Installed.
                           [01]: KB5013890
                           [02]: KB5014678
                           [03]: KB5014030
Network Card(s):           1 NIC(s) Installed.
                           [01]: Amazon Elastic Network Adapter
                                 Connection Name: Ethernet 3
                                 DHCP Enabled:    Yes
                                 DHCP Server:     172.31.0.1
                                 IP address(es)
                                 [01]: 172.31.5.204
                                 [02]: fe80::adef:90c8:43b:77a7
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

# WSLのデフォルトバージョンが2であることを確認
# カーネルのバージョンが表示されることを確認
PS C:\Windows\system32> wsl --status
Default Version: 2

Windows Subsystem for Linux was last updated on 6/24/2022
The Windows Subsystem for Linux kernel can be manually updated with 'wsl --update', but automatic updates cannot occur due to your system settings.
To receive automatic kernel updates, please enable the Windows Update setting: 'Receive updates for other Microsoft products when you update Windows'.
For more information please visit https://aka.ms/wsl2kernel.

Kernel version: 5.10.16

# WSL 2でディストリビューションがインストールされているか確認
PS C:\Windows\system32> wsl -l -v
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

WSLのデフォルトバージョンが2であり、カーネルのバージョンも表示されることからWSL 2の設定がされたようです。なお、VirtualMachinePlatformを有効化した影響か、システム情報を確認すると、Hyper-Vに必要な機能が表示されなくなりました。

下準備が済んだので、ディストリビューションのインストールをします。今回はUbuntuにしました。

PS C:\Users\Administrator> wsl --install --distribution Ubuntu
Downloading: Ubuntu
Installing: Ubuntu
Ubuntu has been installed.
Launching Ubuntu...

インストールが完了すると、Ubuntuのウィンドウが起動し、ユーザー名の入力が求められました。

インストールが完了すると、Ubuntuのウィンドウが起動し、ユーザー名の入力が求められる

ユーザー名やパスワードを入力すると、Ubuntu 20.04が起動しました。圧倒的に簡単ですね。

Ubuntuの起動確認

Windows Terminalからのアクセス

ふと、Windows TerminalからUbuntuにアクセスできるか気になったので、Windows Terminalをインストールをしてみます。

当初、Windows Terminalのインストールは以下記事を参考に最新のバージョンをインストールしようとしました。

しかし、最新のWindows Terminalが求めるビルドバージョンが噛み合わないため、インストールしようとするとエラーになります。

# 最新のWindows Terminalのインストール
PS C:\Users\Administrator> function Install-LatestWindowsTerminal () {
    # Find the latest MSIX installer url
    $latest = Invoke-RestMethod -Uri 'https://api.github.com/repos/microsoft/terminal/releases/latest'
    $msixUrl = $latest.assets | Where-Object { $_.browser_download_url -like '*.msixbundle' } | Select-Object -ExpandProperty browser_download_url -Last 1

    # Download MSIX
    Write-Host -ForegroundColor Green "Download $msixUrl"
    $msixPath = Join-Path -Path ([IO.Path]::GetTempPath()) ($msixUrl -split '/')[-1]
    Invoke-WebRequest -Uri $msixUrl -OutFile $msixPath

    # Install MSIX
    Write-Host -ForegroundColor Green "Install $msixPath"
    Add-AppxPackage -Path $msixPath

    # Remove MSIX
    if (Test-Path -LiteralPath $msixPath) {
        Write-Host -ForegroundColor Green "Remove $msixPath"
        Remove-Item -LiteralPath $msixPath
    }
    Write-Host -ForegroundColor Green "Installation complete!"
}
PS C:\Users\Administrator> Install-LatestWindowsTerminal

Download https://github.com/microsoft/terminal/releases/download/v1.13.11431.0/Microsoft.WindowsTerminal_Win11_1.13.11432.0_8wekyb3d8bbwe.msixbundle
Install C:\Users\Administrator\AppData\Local\Temp\2\Microsoft.WindowsTerminal_Win11_1.13.11432.0_8wekyb3d8bbwe.msixbundle
Add-AppxPackage : Deployment failed with HRESULT: 0x80073CFD, A Prerequisite for an install could not be satisfied.
Windows cannot install package Microsoft.WindowsTerminal_1.13.11432.0_x64__8wekyb3d8bbwe because this package is not
compatible with the device. The package requires OS version 10.0.22000.0 or higher on the Windows.Desktop device
family. The device is currently running OS version 10.0.20348.768.
NOTE: For additional information, look for [ActivityId] 3750ba21-876b-001a-4fc5-50376b87d801 in the Event Log or use
the command line Get-AppPackageLog -ActivityID 3750ba21-876b-001a-4fc5-50376b87d801
At line:13 char:5
+     Add-AppxPackage -Path $msixPath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (C:\Users\Admini...bbwe.msixbundle:String) [Add-AppxPackage], Exception
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

Remove C:\Users\Administrator\AppData\Local\Temp\2\Microsoft.WindowsTerminal_Win11_1.13.11432.0_8wekyb3d8bbwe.msixbundle
Installation complete!

そのため、こちらのブログに記載のバージョンのWindows Terminalをインストールしました。

# Windows Terminalのインストーラーのダウンロード
PS C:\Users\Administrator> Invoke-WebRequest -Uri https://github.com/microsoft/terminal/releases/download/v1.7.1091.0/Microsoft.WindowsTerminal_1.7.1091.0_8wekyb3d8bbwe.msixbundle -outfile Microsoft.WindowsTerminal_1.7.1091.0_8wekyb3d8bbwe.msixbundle

# Windows Terminalのインストール
PS C:\Users\Administrator> Add-AppxPackage -Path .\Microsoft.WindowsTerminal_1.7.1091.0_8wekyb3d8bbwe.msixbundle

インストール後、Windows TerminalからUbuntuにアクセスします。

Ubuntuの選択

Ubuntuの起動

問題なく操作できますね。

Windows Server 2022でもWSL 2は使えるぞ

Windows Server 2022のEC2インスタンスでWSL 2を起動してみました。

wsl --installで簡単に設定できるのが非常に嬉しいですね。WindowsのクライアントOSを持っていない私でもWSL 2ライフを送ることができそうです。

そもそものWSL 2の機能について知りたい方は以下ドキュメントをご覧ください。

この記事が誰かの助けになれば幸いです。

以上、AWS事業本部 コンサルティング部の のんピ(@non____97)でした!

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.